function swap(arr, i, j) {
    const temp = arr[i];
    arr[i] = arr[j];
    arr[j] = temp;
  }
  
  function divide(arr, start, end) {
    const pivot = arr[start];
    
    let i = start + 1;
    let j = end;
    while (i <= j) {
      if(arr[i] < pivot) {
        i++;
      } else if(arr[j] >= pivot) {
        j--;
      } else {
        swap(arr, i++, j--);
      }
    }
    swap(arr, start, i - 1);
    return i - 1;
  }
  
  function quickSort(input, start=0, end=input.length-1) {
    if (start < end) {
      const pivot = divide(input, start, end);
      quickSort(input, start, pivot - 1);
      quickSort(input, pivot + 1, end);
    }
    
    return input;
}

console.log(quickSort([2,1,5,3,9,8,6,3]));